package com.ruoyi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;

/**
 * @author xuxueli 2018-10-28 00:38:13
 */
@SpringBootApplication
public class XxlJobExecutorApplication {

	private static Logger logger = LoggerFactory.getLogger(XxlJobExecutorApplication.class);
	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext applicationContext = SpringApplication.run(XxlJobExecutorApplication.class, args);
		// 获取本地 ip 地址
		String ip = InetAddress.getLocalHost().getHostAddress();
		// 获取服务配置文件，name、port、以及全局服务路径
		Environment env = applicationContext.getEnvironment();
		String name = env.getProperty("spring.application.name");
		String port = env.getProperty("server.port");
		String path = Optional.ofNullable(env.getProperty("server.servlet.context-path")).orElse("");
		// 打印输出
		logger.info("\n----------------------------------------------------------\n\t" +
				"Application " + name +" is running! Access URLs:\n\t" +
				"Local 访问网址: \t\thttp://localhost:" + port + path + "\n\t" +
				"External 访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
				"----------------------------------------------------------");
	}

}